Skip to content

[Compilation] Add Unit Tests for VllmFusionPatternMatcherPass#39692

Merged
ProExpertProg merged 1 commit intovllm-project:mainfrom
EmbeddedLLM:fusion-pm-tests
Apr 16, 2026
Merged

[Compilation] Add Unit Tests for VllmFusionPatternMatcherPass#39692
ProExpertProg merged 1 commit intovllm-project:mainfrom
EmbeddedLLM:fusion-pm-tests

Conversation

@BadrBasowid
Copy link
Copy Markdown
Contributor

@BadrBasowid BadrBasowid commented Apr 13, 2026

Purpose

Adds unit tests for VllmFusionPatternMatcherPass covering:

  • uuid is stable across instances with the same pattern types and differs for different types.
  • matched_count and match_table reflect the correct number of matched patterns.

Test Plan

Run the tests.

Test Result

======================== 5 passed, 18 warnings in 4.64s ========================

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: BadrBasowid <badr.basowid@gmail.com>
@BadrBasowid
Copy link
Copy Markdown
Contributor Author

cc @ProExpertProg

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces unit tests for the VllmFusionPatternMatcherPass, covering pattern registration, UUID stability, and match counting during compilation. A review comment points out that using torch.set_default_device and torch.set_default_dtype modifies global state, which can lead to test flakiness; it suggests using explicit device and dtype placement for models and tensors instead.

Comment on lines +117 to +125
torch.set_default_device("cuda")
torch.set_default_dtype(torch.float32)

fusion_pass = ReluFusionPass(vllm_config)
backend = TestBackend(fusion_pass)
model = torch.compile(Model(), backend=backend)

inputs = [torch.rand(8) for _ in range(N)]
model(*inputs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using torch.set_default_device("cuda") and torch.set_default_dtype(torch.float32) modifies global state that persists after the test completes. This can lead to unexpected side effects and flakiness in other tests that expect the default CPU device or a different default dtype. It is better to use explicit device and dtype placement for the model and tensors.

Suggested change
torch.set_default_device("cuda")
torch.set_default_dtype(torch.float32)
fusion_pass = ReluFusionPass(vllm_config)
backend = TestBackend(fusion_pass)
model = torch.compile(Model(), backend=backend)
inputs = [torch.rand(8) for _ in range(N)]
model(*inputs)
fusion_pass = ReluFusionPass(vllm_config)
backend = TestBackend(fusion_pass)
model = torch.compile(Model().to("cuda"), backend=backend)
inputs = [torch.rand(8, device="cuda", dtype=torch.float32) for _ in range(N)]
model(*inputs)

@ProExpertProg ProExpertProg enabled auto-merge (squash) April 16, 2026 22:08
@github-actions github-actions Bot added the ready ONLY add when PR is ready to merge/full CI is needed label Apr 16, 2026
@ProExpertProg ProExpertProg merged commit 29057d3 into vllm-project:main Apr 16, 2026
18 of 19 checks passed
vllm-agent pushed a commit to vllm-agent/vllm that referenced this pull request Apr 17, 2026
bnellnm pushed a commit to neuralmagic/vllm that referenced this pull request Apr 20, 2026
baonudesifeizhai pushed a commit to baonudesifeizhai/vllm that referenced this pull request Apr 23, 2026
whk-lab pushed a commit to whk-lab/vllm that referenced this pull request Apr 23, 2026
avinashsingh77 pushed a commit to avinashsingh77/vllm that referenced this pull request Apr 27, 2026
…roject#39692)

Signed-off-by: BadrBasowid <badr.basowid@gmail.com>
Signed-off-by: Avinash Singh <avinashsingh.rcoem@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants